<template>
  <div>
    <h2 style="float:left">{{ this.rowObj.inspectionDate }}</h2>
    <el-button style="float:right;margin-top: 15px;" icon="el-icon-download" @click="download" type="warning" plain>下载
    </el-button>
    <el-table :data="List" style="width: 100%">
      <el-table-column v-for="(item, index) in ValueList" :key="index" :prop="`presets${index}`" :label="item"
        min-width="130px" show-overflow-tooltip>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getonlineList, getonlineaddList, downloadList } from "@/api/record/index.js";
// import { listUser } from "@/api/system/user.js";

import { formatDateIndex } from '@/utils/index.js'
export default {
  props: ['title', 'rowObj'],
  components: {
    // Upload
  },
  data () {
    return {
      isshow: false,
      ValueList: [],
      List: [],
      realTime: formatDateIndex(new Date()),
      typeList: [],
    }
  },
  computed: {
  },
  created () {
    this.getlist()
  },
  methods: {
    async download () {
      let name = '线上巡检记录列表.xlsx';
      let params = {
        'params[beginTime]': this.rowObj.inspectionDate,
        'params[endTime]': this.rowObj.inspectionDate
      }
      await downloadList(params, name)
    },
    async getlist () {
      let params = {
        'params[beginTime]': this.rowObj.inspectionDate,
        'params[endTime]': this.rowObj.inspectionDate
      }
      let query = {
        ascription: '2'
      }
      let { data: user } = await getonlineList(params)
      let { data: add } = await getonlineaddList(query)
      this.List = user
      this.ValueList = add.filter((item, index) => {
        if (index < 8) {
          return item
        }
      }).map(item => item.projectDescribe)
      this.ValueList.unshift('时间')
      this.ValueList.push('巡检人', '问题清单')
    },
    handlerParent (id) {
      this.typeList.forEach(element => {
        if (element.id === id) {
          this.form.ascription = element.ascription
        }
      });
    },
    //提交
    submitForm () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          // for (let index = 0; index < this.form.inspectionPlaceRecordAbnormalList.length; index++) {
          //   const e = this.form.inspectionPlaceRecordAbnormalList[index];
          //   if ((!e.faultDescribe) || !e.faultHandleDescribe || !e.handleUserId || !e.handleTime) {
          //     return this.$message.error(`请将列表内序号为${index + 1}的数据填写完整`)
          //   }
          // }
          if (this.title === '修改记录') {//修改
            let params = {
              ...this.form,
              recordJsonData: JSON.stringify(this.ValueList)
            }
            Updaterecord(params).then(res => {
              if (res.code === 200) {
                this.$message.success(res.msg)
                this.clear()

              }
            })
          } else {//新增
            let params = {
              ...this.form,
              recordJsonData: JSON.stringify(this.ValueList)
            }
            Createdrecord(params).then(res => {
              if (res.code === 200) {
                this.$message.success(res.msg)
                this.clear()
              }
            })
          }
        }
      });
    },
    handleadd () {
      this.form.inspectionPlaceRecordAbnormalList.push({
        "faultDescribe": undefined,        //故障描述
        "faultHandleDescribe": undefined,  //异常处理描述
        "handleUser": undefined, //处理人
        "handleTime": undefined  //处理时间
      })
    },
    handleDelete (index) {
      this.form.inspectionPlaceRecordAbnormalList.splice(index, 1)
    },
    clear () {
      this.$emit('quit')
    }
  }
}
</script>

<style lang="scss" scoped>

</style>